﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace ServiceCountdown
{
    public partial class CountdownWindow : Window
    {
        private TimeSpan time;
        private DispatcherTimer dispatcherTimer;

        public CountdownWindow(string message, int minutes)
        {
            InitializeComponent();

            time = TimeSpan.FromMinutes(minutes);
            txtDisplay.Text = time.ToString();
            txtMessage.Text = message;

            dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
            dispatcherTimer.Start();
        }

        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            if (time.TotalSeconds == 0)
                return;
            time = time.Subtract(TimeSpan.FromSeconds(1));
            txtDisplay.Text = time.ToString();
        }
    }
}
